﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;

using H2.NET.Controls;
using H2.NET.Business;
using H2.NET.Data.Common;

namespace H2.NET.Web.Pages
{
    public partial class PGLA : TaskPage
    {
        #region 属性 Public
        private bool IsLoaded
        {
            get
            {
                return ViewState["IsLoaded"] == null ? false : (bool)ViewState["IsLoaded"];
            }
            set { ViewState["IsLoaded"] = value; }
        }
        #endregion

        #region 事件 Page_Load(页面加载)
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                INFO.Text = string.Format("<br/>表单正在被同事“{0}”抢占处理，拒绝提交！", RobUser);
                INFO.Visible = IsOverFlow;

                //InitDropDownList();
                bool flg = (TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit) ? true : false;

                #region 发起步骤
                if ((TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit))
                {
                    InitDropDownList();
                    SetColor();
                }
                #endregion

                #region 审批环节
                if (!TaskAPI.IsInitiate)
                {
                    #region 加载数据并显示
                    gla_GLAccount account = (gla_GLAccount.process == TaskAPI.Process & gla_GLAccount.incident == TaskAPI.Incident).ListFirst<gla_GLAccount>();
                    if (account != null)
                    {
                        SetDropDownListValue(Actions, account.Actions);
                        SetColor();
                        ApplicationNo.Text = account.ApplicationNo;
                        Actions.SelectedValue = account.Actions;
                        SetDropDownListValue(DrpPriority, account.DrpPriority);
                        IS_GL_Account.Text = account.IS_GL_Account;

                        RE_GL_Account.Text = account.RE_GL_Account;


                        SetDropDownListValue(Account_Currency, account.Account_Currency);
                        Only_Balance.Checked = account.Only_Balance == "1";
                        IS_1718.Checked = account.IS_1718 == "1";
                        IS_4118.Checked = account.IS_4118 == "1";
                        IS_4119.Checked = account.IS_4119 == "1";
                        IS_8856.Checked = account.IS_8856 == "1";
                        IS_4127.Checked = account.IS_4127 == "1";
                        IS_1925.Checked = account.IS_1925 == "1";
                        IS_8118.Checked = account.IS_8118 == "1";
                        IS_8718.Checked = account.IS_8718 == "1";
                        RE_1718.Checked = account.RE_1718 == "1";
                        RE_4118.Checked = account.RE_4118 == "1";
                        RE_4119.Checked = account.RE_4119 == "1";
                        RE_8856.Checked = account.RE_8856 == "1";
                        RE_4127.Checked = account.RE_4127 == "1";
                        RE_1925.Checked = account.RE_1925 == "1";
                        RE_8118.Checked = account.RE_8118 == "1";
                        RE_8718.Checked = account.RE_8718 == "1";

                        Tax_Category.SelectedValue = account.Tax_Category;
                        Without_Tax.Checked = account.Without_Tax == "1";
                        Recon_Account.SelectedValue = account.Recon_Account;
                        Account_No.Text = account.Account_No;
                        Open_Item.Checked = account.Open_Item == "1";
                        Line_Item.Checked = account.Line_Item == "1";
                        Sort_key.Text = account.Sort_key;
                        Accounting_Clerk.SelectedValue = account.Accounting_Clerk;
                        SetDropDownListValue(Field_Status_Group, account.Field_Status_Group);

                        Post_Automatically_Only.Checked = account.Post_Automatically_Only == "1";
                        SetDropDownListValue(Planning_Level, account.Planning_Level);

                        Relevant_To_Cash.Checked = account.Relevant_To_Cash == "1";
                        SetDropDownListValue(Cost_Element_Category, account.Cost_Element_Category);
                        SetDropDownListValue(Cost_Element_Group, account.Cost_Element_Group);
                        Financial_Statement.Text = account.Financial_Statement;
                        SetDropDownListValue(Yes_No, account.Yes_No);
                        if (flg)
                        {
                            Yes_No_SelectedIndexChanged(null, e);
                        }

                        SetDropDownListValue(DMO_DrpPriority, account.DMO_DrpPriority);
                        DMO_Arrpvoe_Creation_Number.Text = account.DMO_Arrpvoe_Creation_Number;
                        DMO_Arrpvoe_Creation_Time.Text = account.DMO_Arrpvoe_Creation_Time;
                        DMO_Maintain_Creation_Number.Text = account.DMO_Maintain_Creation_Number;
                        DMO_Maintain_Creation_Time.Text = account.DMO_Maintain_Creation_Time;
                        DMO_Check_Creation_Number.Text = account.DMO_Check_Creation_Number;
                        DMO_Check_Creation_Time.Text = account.DMO_Check_Creation_Time;
                        DMO_Arrpvoe_Revision_Number.Text = account.DMO_Arrpvoe_Revision_Number;
                        DMO_Arrpvoe_Revision_Time.Text = account.DMO_Arrpvoe_Revision_Time;
                        DMO_Maintain_Revision_Number.Text = account.DMO_Maintain_Revision_Number;
                        DMO_Maintain_Revision_Time.Text = account.DMO_Maintain_Revision_Time;
                        DMO_Check_Revision_Number.Text = account.DMO_Check_Revision_Number;
                        DMO_Check_Revision_Time.Text = account.DMO_Check_Revision_Time;


                    }
                    #endregion

                    #region 审批项初始化
                    switch (TaskAPI.Step)
                    {
                        case "DMO Approve":
                        case "DMO Maintain":
                        case "DMO Check":
                            Assessment1.Option.Add(new t_AssessmentOption("Finish", "1", true));
                            Assessment1.Option.Add(new t_AssessmentOption("Return", "2", false));
                            break;
                        case "Manager Approve":
                            Assessment1.Option.Add(new t_AssessmentOption("Approve", "1", true));
                            Assessment1.Option.Add(new t_AssessmentOption("Return", "2", false));

                            break;
                    }
                    #endregion
                }
                #endregion

                SetDefaultValue();

                #region 设置控件禁启用
                //bool flg = (TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit) ? true : false;

                SetEnable(flg, DrpPriority, IS_1718, IS_4118, IS_4119, Actions, IS_8856, IS_4127, IS_1925, IS_8118, IS_8718, RE_1718, RE_4118, RE_4119, RE_8856, RE_4127, RE_1925, RE_8118, RE_8718, Financial_Statement, IS_GL_Account, RE_GL_Account, Account_Currency, Only_Balance, Tax_Category, Without_Tax, Recon_Account, Account_No, Open_Item, Accounting_Clerk, Field_Status_Group, Post_Automatically_Only, Planning_Level, Relevant_To_Cash, Yes_No, Cost_Element_Category, Cost_Element_Group);
                //SetEnable(TaskAPI.Step == "DMO Maintain", SAP_Code);
                SetEnable(TaskAPI.Step == "DMO Approve" | TaskAPI.Step == "DMO Maintain" | TaskAPI.Step == "DMO Check", DMO_DrpPriority, DMO_Arrpvoe_Creation_Number, DMO_Arrpvoe_Creation_Time, DMO_Maintain_Creation_Number, DMO_Maintain_Creation_Time, DMO_Check_Creation_Number, DMO_Check_Creation_Time, DMO_Arrpvoe_Revision_Number, DMO_Arrpvoe_Revision_Time, DMO_Maintain_Revision_Number, DMO_Maintain_Revision_Time, DMO_Check_Revision_Number, DMO_Check_Revision_Time);
                SetVisible(TaskAPI.Step == "DMO Approve" | TaskAPI.Step == "DMO Maintain" | TaskAPI.Step == "DMO Check", P_DMO);


                Assessment1.Enable = TaskAPI.IsAllowSubmit;
                SetVisible(TaskAPI.IsAllowSubmit, Send, Split);

                //if (TaskAPI.Step == "DMO Approve")
                //{
                //    SetForeColor(Color.Blue, DMO_DrpPriority_L);
                //}

                //if (TaskAPI.Step == "DMO Approve" & Actions.SelectedValue == "1")
                //{
                //    SetForeColor(Color.Blue, DMO_Arrpvoe_Creation_L);
                //}
                //if (TaskAPI.Step == "DMO Maintain" & Actions.SelectedValue == "1")
                //{
                //    SetForeColor(Color.Blue, DMO_Maintain_Creation_L);
                //}
                //if (TaskAPI.Step == "DMO Check" & Actions.SelectedValue == "1")
                //{
                //    SetForeColor(Color.Blue, DMO_Check_Creation_L);
                //}
                //if (TaskAPI.Step == "DMO Approve" & Actions.SelectedValue != "1")
                //{
                //    SetForeColor(Color.Blue, DMO_Arrpvoe_Revision_L);
                //}
                //if (TaskAPI.Step == "DMO Maintain" & Actions.SelectedValue != "1")
                //{
                //    SetForeColor(Color.Blue, DMO_Maintain_Revision_L);
                //}
                //if (TaskAPI.Step == "DMO Check" & Actions.SelectedValue != "1")
                //{
                //    SetForeColor(Color.Blue, DMO_Check_Revision_L);
                //}

                Attachment1.AllowDelete = TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit;
                Attachment1.AllowUpload = TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit;
                //InitTabs();
                #endregion

                #region 加深颜色
                string item = null;
                string value = null;
                foreach (Control cr in this.Controls)
                {
                    if (cr is DropDownList)
                    {
                        DropDownList tb = (DropDownList)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            item = tb.SelectedItem.Text;
                            value = tb.SelectedValue.ToString();
                            tb.Items.Clear();
                            tb.Items.Add(new ListItem(item, value));
                        }
                        tb.ForeColor = System.Drawing.Color.DimGray;
                    }
                }
                if (!flg || !TaskAPI.IsAllowSubmit)
                {

                    foreach (Control cr in form.Controls)
                    {
                        if (cr is DropDownList)
                        {
                            DropDownList tb = (DropDownList)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                item = tb.SelectedItem.Text;
                                value = tb.SelectedValue.ToString();
                                tb.Items.Clear();
                                tb.Items.Add(new ListItem(item, value));
                            }
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                    foreach (Control cr in form.Controls)
                    {
                        if (cr is TextBox)
                        {
                            TextBox tb = (TextBox)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                tb.ReadOnly = true;
                                tb.ForeColor = System.Drawing.Color.DimGray;
                            }
                        }
                    }

                }

                #endregion
            }
        }
        #endregion

        #region 事件 Send
        protected void Send_Click(object sender, EventArgs e)
        {
            try
            {
                #region 数据验证
                if ((TaskAPI.IsBeginStep || TaskAPI.Step == "DMO Maintain" || TaskAPI.Step == "DMO Check" || TaskAPI.Step == "DMO Approve") && TaskAPI.IsAllowSubmit) // 如果是退回的情况，不存在验证
                {
                    List<string> vald_s = new List<string>();
                    vald_s.AddRange(DataValidation());
                    if (vald_s.Count > 0)
                    {
                        Anthem.Manager.AddScriptForClientSideEval(string.Format("ShowMessage(\"{0}\", {1});", CombineMessage(vald_s), vald_s.Count));
                        return;
                    }
                }
                #endregion

                #region 引擎传值
                if (TaskAPI.IsBeginStep)
                {
                    if (TaskAPI.IsInitiate)
                    {
                        ApplicationNo.Text = Util.GenerateSequence(((object[])TaskAPI["PrefixNo"])[0].ToString() + "-" + System.DateTime.Now.ToString("yyMM"), "", 4);
                        TaskAPI.UserName = UserAPI.UserName;
                        TaskAPI["ApplicationNo"] = ApplicationNo.Text;
                        TaskAPI["ApplicatorName"] = UserAPI.UserFullName;
                        TaskAPI["Applicator"] = UserAPI.UserName;
                        TaskAPI["Time"] = System.DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss");
                        TaskAPI["ApplicatorEmail"] = UserAPI.Mail;
                        TaskAPI["Department"] = UserAPI.Department;
                        TaskAPI["ServerName"] = Util.AppSettings("ServerName");
                    }

                    TaskAPI.Summary = (Actions.SelectedItem.Text.Split(',').Length >= 2 ? Actions.SelectedItem.Text.Split(',')[1].Trim() : Actions.Text) + " / " + ApplicationNo.Text;

                    TaskAPI["Actions"] = Actions.SelectedValue;
                    TaskAPI["Remark_by_Initiator"] = Assessment1.Assessment.Remark;
                    TaskAPI["DrpPriority"] = DrpPriority.SelectedItem.Text;

                    #region 从数据库取得流程步骤处理人
                    SortedList<string, string> rec_a = new SortedList<string, string>();

                    IList<mdc_Recipient> rec_s = (mdc_Recipient.process == TaskAPI.Process & (mdc_Recipient.distribute == Actions.SelectedValue | mdc_Recipient.distribute == "*") & mdc_Recipient.status == 1).List<mdc_Recipient>();
                    foreach (mdc_Recipient rec in rec_s)
                    {
                        if (!rec_a.ContainsKey(rec.Step))
                        {
                            rec_a.Add(rec.Step, rec.Recipient);
                            continue;
                        }

                        if (rec_a.Values[rec_a.IndexOfKey(rec.Step)].Contains(rec.Recipient))
                        {
                            continue;
                        }

                        rec_a[rec.Step] = rec_a.Values[rec_a.IndexOfKey(rec.Step)] + "," + rec.Recipient;
                    }

                    //步骤处理人赋值
                    for (int i = 0; i < rec_a.Keys.Count; i++)
                    {
                        TaskAPI["R_" + rec_a.Keys[i].Replace(" ", "_")] = rec_a.Values[i].Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    }

                    m_OrgChart oc = (m_OrgChart.empID.In(m_OrgChart.dr2EmpID, m_OrgChart.winID == UserAPI.UserName)).ListFirst<m_OrgChart>();
                    if (oc != null)
                    {
                        TaskAPI["R_Manager_Approve"] = oc.WinID;
                    }

                    #endregion
                }
                else
                {
                    TaskAPI["ApproveResult"] = Assessment1.Assessment.Opinion;
                    TaskAPI["TaskID"] = TaskAPI.TaskID;
                }

                //if (TaskAPI.IsBeginStep && !TaskAPI.IsInitiate
                //&& (Action_Type != Actions.SelectedValue || account_Type != VD_account_Type.SelectedValue))
                //{
                //    string PreStep = ((object[])TaskAPI["PreStep"])[0].ToString();
                //    if (PreStep.Trim() != "" && PreStep.Trim() != "Manager Approve")
                //    {
                //        TaskAPI["PreStep"] = "DMO Approve";
                //    }
                //}

                //#region 退回步骤并返回功能 传值
                //if (!string.IsNullOrEmpty(Assessment1.JumpStep))
                //{
                //    TaskAPI["Step"] = Assessment1.JumpStep;
                //    TaskAPI["PreStep"] = TaskAPI.Step;
                //}
                //else
                //{
                //    string PreStep = ((object[])TaskAPI["PreStep"])[0].ToString();
                //    if (PreStep.Trim() != "")
                //    {
                //        TaskAPI["Step"]    = PreStep;
                //        TaskAPI["PreStep"] = "";
                //    }
                //    else
                //    {
                //        TaskAPI["Step"] = "";
                //        TaskAPI["PreStep"] = "";
                //    }
                //}
                //#endregion

                #endregion

                #region 提交步骤
                bool flg = false;
                Storage.TransactionExecute(o =>
                {
                    #region “Fill in the form”步骤
                    if (TaskAPI.IsBeginStep)
                    {
                        gla_GLAccount account = new gla_GLAccount();
                        if ((gla_GLAccount.process == TaskAPI.Process & gla_GLAccount.incident == TaskAPI.Incident & gla_GLAccount.userName == UserAPI.UserName).Count<gla_GLAccount>() > 0)
                        {
                            account = (gla_GLAccount.process == TaskAPI.Process & gla_GLAccount.incident == TaskAPI.Incident & gla_GLAccount.userName == UserAPI.UserName).ListFirst<gla_GLAccount>();
                        }
                        else
                        {
                            account.Process = TaskAPI.Process;
                            account.Incident = TaskAPI.Incident;
                            account.UserName = UserAPI.UserName;
                            account.UserFullName = UserAPI.UserFullName;
                            account.ApplicationNo = ApplicationNo.Text;
                            account.Time = System.DateTime.Now;
                            account.Status = 0;
                            account.Department = UserAPI.Department;
                        }

                        account.Actions = Actions.SelectedValue;
                        account.Actions = Actions.SelectedItem.Text;

                        account.Actions = Actions.SelectedValue;
                        account.DrpPriority = DrpPriority.SelectedValue;
                        account.IS_GL_Account = IS_GL_Account.Text;
                        //account.IS_Company_Code   = IS_Company_Code.SelectedValue;
                        account.RE_GL_Account = RE_GL_Account.Text;
                        //account.RE_Company_Code   = RE_Company_Code.SelectedValue;
                        account.Account_Currency = Account_Currency.SelectedValue;
                        account.Only_Balance = Only_Balance.Checked ? "1" : "0";
                        account.Tax_Category = Tax_Category.SelectedValue;
                        account.Without_Tax = Without_Tax.Checked ? "1" : "0";
                        account.Recon_Account = Recon_Account.SelectedValue;
                        account.Account_No = Account_No.Text;
                        account.Open_Item = Open_Item.Checked ? "1" : "0";
                        account.Line_Item = Line_Item.Checked ? "1" : "0";
                        account.Sort_key = Sort_key.Text;
                        account.Accounting_Clerk = Accounting_Clerk.SelectedValue;
                        account.Field_Status_Group = Field_Status_Group.SelectedValue;
                        account.Post_Automatically_Only = Post_Automatically_Only.Checked ? "1" : "0";
                        account.Planning_Level = Planning_Level.SelectedValue;
                        account.Relevant_To_Cash = Relevant_To_Cash.Checked ? "1" : "0";
                        account.Yes_No = Yes_No.SelectedValue;
                        account.Cost_Element_Category = Cost_Element_Category.SelectedValue;
                        account.Cost_Element_Group = Cost_Element_Group.SelectedValue;
                        account.Financial_Statement = Financial_Statement.Text;
                        account.IS_1718 = IS_1718.Checked ? "1" : "0";
                        account.IS_4118 = IS_4118.Checked ? "1" : "0";
                        account.IS_4119 = IS_4119.Checked ? "1" : "0";
                        account.IS_8856 = IS_8856.Checked ? "1" : "0";
                        account.IS_4127 = IS_4127.Checked ? "1" : "0";
                        account.IS_1925 = IS_1925.Checked ? "1" : "0";
                        account.IS_8118 = IS_8118.Checked ? "1" : "0";
                        account.IS_8718 = IS_8718.Checked ? "1" : "0";
                        account.RE_1718 = RE_1718.Checked ? "1" : "0";
                        account.RE_4118 = RE_4118.Checked ? "1" : "0";
                        account.RE_4119 = RE_4119.Checked ? "1" : "0";
                        account.RE_8856 = RE_8856.Checked ? "1" : "0";
                        account.RE_4127 = RE_4127.Checked ? "1" : "0";
                        account.RE_1925 = RE_1925.Checked ? "1" : "0";
                        account.RE_8118 = RE_8118.Checked ? "1" : "0";
                        account.RE_8718 = RE_8718.Checked ? "1" : "0";



                        (t_Attachment.process == TaskAPI.Process & t_Attachment.incident == 0 & t_Attachment.username == UserAPI.UserName).Edit<t_Attachment>(p =>
                        {
                            p.Incident = TaskAPI.Incident;
                        });

                        Storage.Save(Storage.Context1, account);
                    }
                    #endregion
                    #region Priority功能
                    if (TaskAPI.IsBeginStep && !string.IsNullOrEmpty(DrpPriority.SelectedValue))
                    {
                        mdc_Priority pro;
                        if ((mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).Count<mdc_Priority>() > 0)
                        {
                            pro = new mdc_Priority();
                            pro = (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).ListFirst<mdc_Priority>();
                            pro.Business_Priority = Convert.ToInt32(DrpPriority.SelectedValue);
                            Storage.Save(pro);
                        }
                        else
                        {
                            pro = new mdc_Priority();
                            pro.Process = TaskAPI.Process;
                            pro.Incident = TaskAPI.Incident;
                            pro.Business_Priority = Convert.ToInt32(DrpPriority.SelectedValue);
                            Storage.Save(pro);
                        }

                    }


                    if ((TaskAPI.Step == "DMO Maintain" || TaskAPI.Step == "DMO Approve" || TaskAPI.Step == "DMO Check") && !string.IsNullOrEmpty(this.DMO_DrpPriority.SelectedValue) && !string.IsNullOrEmpty(DrpPriority.SelectedValue))
                    {

                        //mdc_Priority pro;
                        //pro = (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).ListFirst<mdc_Priority>();
                        //pro.DMO_Priority = Convert.ToInt32(DMO_DrpPriority.SelectedValue);
                        //Storage.Save(pro);
                        mdc_Priority pro;
                        if ((mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).Count<mdc_Priority>() > 0)
                        {
                            pro = (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).ListFirst<mdc_Priority>();
                            pro.DMO_Priority = Convert.ToInt32(DMO_DrpPriority.SelectedValue);
                            Storage.Save(pro);
                        }
                        else
                        {
                            pro = (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).ListFirst<mdc_Priority>();
                            pro.DMO_Priority = Convert.ToInt32(DMO_DrpPriority.SelectedValue);
                            Storage.Save(pro);
                        }


                    }
                    #endregion
                    //#region “DMO Maintain”步骤
                    //if (TaskAPI.Step == "DMO Maintain")
                    //{
                    //    (gla_GLAccount.process == TaskAPI.Process & gla_GLAccount.incident == TaskAPI.Incident).Edit<gla_GLAccount>(p =>
                    //    {
                    //        p.SAP_Code = SAP_Code.Text;
                    //    }    
                    //    );
                    //}
                    //#endregion
                    #region “DMO Maintain”步骤
                    if (TaskAPI.Step == "DMO Maintain" || TaskAPI.Step == "DMO Approve" || TaskAPI.Step == "DMO Check")
                    {

                        TaskAPI["DMO_DrpPriority"] = DMO_DrpPriority.SelectedItem.Text;
                        (gla_GLAccount.process == TaskAPI.Process & gla_GLAccount.incident == TaskAPI.Incident).Edit<gla_GLAccount>(p =>
                        {
                            // p.SAP_Code = SAP_Code.Text;
                            p.DMO_DrpPriority = DMO_DrpPriority.SelectedValue;
                            p.DMO_Arrpvoe_Creation_Number = DMO_Arrpvoe_Creation_Number.Text;
                            p.DMO_Arrpvoe_Creation_Time = DMO_Arrpvoe_Creation_Time.Text;
                            p.DMO_Maintain_Creation_Number = DMO_Maintain_Creation_Number.Text;
                            p.DMO_Maintain_Creation_Time = DMO_Maintain_Creation_Time.Text;
                            p.DMO_Check_Creation_Number = DMO_Check_Creation_Number.Text;
                            p.DMO_Check_Creation_Time = DMO_Check_Creation_Time.Text;
                            p.DMO_Arrpvoe_Revision_Number = DMO_Arrpvoe_Revision_Number.Text;
                            p.DMO_Arrpvoe_Revision_Time = DMO_Arrpvoe_Revision_Time.Text;
                            p.DMO_Maintain_Revision_Number = DMO_Maintain_Revision_Number.Text;
                            p.DMO_Maintain_Revision_Time = DMO_Maintain_Revision_Time.Text;
                            p.DMO_Check_Revision_Number = DMO_Check_Revision_Number.Text;
                            p.DMO_Check_Revision_Time = DMO_Check_Revision_Time.Text;

                            //p.DMO_SalesSAP_Code = DMO_SalesSAP_Code.Text;
                        }
                        );
                    }
                    #endregion
                    Storage.Save(Assessment1.Assessment);    //审批意见

                    //多节点退回
                    if (!string.IsNullOrEmpty(Assessment1.JumpStep))
                    {
                        Assessment1.SetAsReturn(true);
                        TaskAPI.DirectActive(Assessment1.JumpStep);
                    }
                    else
                    {
                        Assessment1.SetAsReturn(false);
                    }
                    Assessment1.SubmitTo();

                    flg = TaskAPI.Send();
                });

                //如果数据库写入成功且流程发起成功的情况，将业务表数据与流程实例号进行关联
                if (TaskAPI.IsInitiate)
                {

                    if (!string.IsNullOrEmpty(DrpPriority.SelectedValue))
                    {
                        (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == 0).Edit<mdc_Priority>(p =>
                        {
                            p.Incident = TaskAPI.Incident;
                        });
                    }
                    (gla_GLAccount.process == TaskAPI.Process & gla_GLAccount.incident == 0 & gla_GLAccount.userName == UserAPI.UserName).Edit<gla_GLAccount>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });

                    (t_Assessment.process == TaskAPI.Process & t_Assessment.incident == 0 & t_Assessment.assignedToUserName == UserAPI.UserName).Edit<t_Assessment>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });

                    (t_Attachment.process == TaskAPI.Process & t_Attachment.incident == 0 & t_Attachment.username == UserAPI.UserName).Edit<t_Attachment>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });

                }
                #endregion

                Send.Visible = false;
                Anthem.Manager.AddScriptForClientSideEval("JSInfomation('" + Resources.Global.C_00_Success + "',true)");
            }
            catch (Exception ex)
            {
                TaskDB.Log("", false, "调用NVA方法Send_Click出错：" + ex.ToString());
                Anthem.Manager.AddScriptForClientSideEval("JSInfomation('" + Resources.Global.C_00_Failed + "',false)");
            }
        }
        #endregion

        #region 事件 Actions 变换
        protected void Actions_SelectedIndexChanged(object sender, EventArgs e)
        {
            SetColor();
            SetEnable((Actions.SelectedValue == "1" || Actions.SelectedValue == "2" || Actions.SelectedValue == "3" || Actions.SelectedValue == "4"), DrpPriority, IS_1718, IS_4118, IS_4119, IS_8856, IS_4127, IS_1925, IS_8118, IS_8718, RE_8118, RE_8718, RE_1718, RE_4118, RE_4119, RE_8856, RE_4127, RE_1925, IS_GL_Account, RE_GL_Account, Account_Currency, Only_Balance, Tax_Category, Without_Tax, Recon_Account, Account_No, Open_Item, Accounting_Clerk, Field_Status_Group, Post_Automatically_Only, Planning_Level, Relevant_To_Cash, Yes_No, Cost_Element_Category, Cost_Element_Group);
        }
        #endregion

        #region 方法 SetColor
        protected void SetColor()
        {
            SetForeColor(Color.Black, IS_GL_Account_L, IS_Company_Code_L, Financial_Statement_L, Account_Currency_L, Field_Status_Group_L, Yes_No_L);

            switch (Actions.SelectedValue)
            {
                case "1":
                    SetForeColor(Color.Blue, IS_GL_Account_L, IS_Company_Code_L, Financial_Statement_L, Account_Currency_L, Field_Status_Group_L, Yes_No_L);
                    break;

                case "2":
                    SetForeColor(Color.Blue, IS_GL_Account_L, IS_Company_Code_L);
                    break;

                case "3":
                    SetForeColor(Color.Blue, IS_GL_Account_L, IS_Company_Code_L);
                    break;

                case "4":
                    SetForeColor(Color.Blue, IS_GL_Account_L, IS_Company_Code_L);
                    break;
            }
        }
        #endregion

        #region 方法 SetDefaultValue(设置默认值, 并禁用输入)
        public void SetDefaultValue()
        {
            Line_Item.Checked = true;
            Sort_key.Text = "001,Posting date";
            SetEnable(false, Line_Item, Sort_key);
            SetForeColor(Color.Orange, Line_Item_L, Sort_key_L);
        }
        #endregion

        #region 方法 InitDropdownList
        private void InitDropDownList()
        {
            if (!IsLoaded)
            {
                Account_Currency.Items.Clear();
                Account_Currency.Items.Add(new ListItem("", ""));
                IList<m_Cost_Center_Currency> ccc = (m_Cost_Center_Currency.status == 1).List<m_Cost_Center_Currency>();
                foreach (m_Cost_Center_Currency HY in ccc)
                {
                    Account_Currency.Items.Add(new ListItem(HY.Cost_Center_Currency, HY.Cost_Center_Currency));
                }

                Field_Status_Group.Items.Clear();
                Field_Status_Group.Items.Add(new ListItem("", ""));
                IList<m_Field_Status_Group> fsg = (m_Field_Status_Group.status == 1).List<m_Field_Status_Group>();
                foreach (m_Field_Status_Group HY in fsg)
                {
                    Field_Status_Group.Items.Add(new ListItem(HY.Field_Status_Group, HY.Field_Status_Group));
                }

                Planning_Level.Items.Clear();
                Planning_Level.Items.Add(new ListItem("", ""));
                IList<m_Planning_Level> mpl = (m_Planning_Level.status == 1).List<m_Planning_Level>();
                foreach (m_Planning_Level HY in mpl)
                {
                    Planning_Level.Items.Add(new ListItem(HY.Planning_Level, HY.Planning_Level));
                }

                Cost_Element_Category.Items.Clear();
                Cost_Element_Category.Items.Add(new ListItem("", ""));
                IList<m_GLAccount_Element_Category> gec = (m_GLAccount_Element_Category.status == 1).List<m_GLAccount_Element_Category>();
                foreach (m_GLAccount_Element_Category HY in gec)
                {
                    Cost_Element_Category.Items.Add(new ListItem(HY.Cost_Element_Category, HY.Cost_Element_Category));
                }

                Cost_Element_Group.Items.Clear();
                Cost_Element_Group.Items.Add(new ListItem("", ""));
                IList<m_GLAccount_Element_Group> gec1 = (m_GLAccount_Element_Group.status == 1).List<m_GLAccount_Element_Group>();
                foreach (m_GLAccount_Element_Group HY in gec1)
                {
                    Cost_Element_Group.Items.Add(new ListItem(HY.Cost_Element_Group, HY.Cost_Element_Group));
                }
                IsLoaded = true;
            }
        }
        #endregion

        #region 方法 数据验证
        private List<string> DataValidation()
        {

            List<Regular> regs = new List<Regular>();
            if (Actions.SelectedValue == "1")
            {
                regs.Add(new Regular(RegularExp.NotEmpty, IS_GL_Account.Text, "GL Accountt 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, (!IS_1718.Checked && !IS_4118.Checked && !IS_4119.Checked && !IS_8856.Checked && !IS_4127.Checked && !IS_1925.Checked && !IS_8118.Checked && !IS_8718.Checked ? "" : "NotBlank"), "Company Code 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, Account_Currency.SelectedValue, "Account Currency 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, Field_Status_Group.SelectedValue, "Field Status Group 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, Yes_No.SelectedValue, "Yes / No 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, Financial_Statement.Text, "Financial statement version node (CN00) 必填"));
                if (Yes_No.SelectedValue == "Yes")
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, Cost_Element_Category.SelectedValue, "Cost Element Category 必填"));
                }

            }
            if (Actions.SelectedValue != "1")
            {
                regs.Add(new Regular(RegularExp.NotEmpty, IS_GL_Account.Text, "GL Accountt 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, (!IS_1718.Checked && !IS_4118.Checked && !IS_4119.Checked && !IS_8856.Checked && !IS_4127.Checked && !IS_1925.Checked && !IS_8118.Checked && !IS_8718.Checked ? "" : "NotBlank"), "Company Code 必填"));

            }
            //if (TaskAPI.Step == "DMO Approve" & Assessment1.Assessment.Opinion == "1")
            //{


            //    regs.Add(new Regular(RegularExp.NotEmpty, DMO_DrpPriority.SelectedValue, " Priority 必填"));


            //}


            //if (TaskAPI.Step == "DMO Approve" & Actions.SelectedValue == "1" & Assessment1.Assessment.Opinion == "1")
            //{

            //    if (DMO_Arrpvoe_Creation_Number.Text == "" | DMO_Arrpvoe_Creation_Time.Text == "")
            //    {
            //        regs.Add(new Regular(RegularExp.NotEmpty, "", " DMO Approve的Creation项必填"));
            //    }

            //}
            //if (TaskAPI.Step == "DMO Maintain" & Actions.SelectedValue == "1" & Assessment1.Assessment.Opinion == "1")
            //{

            //    if (DMO_Maintain_Creation_Number.Text == "" | DMO_Maintain_Creation_Time.Text == "")
            //    {
            //        regs.Add(new Regular(RegularExp.NotEmpty, "", " DMO Maintain的Creation项必填"));
            //    }

            //}
            //if (TaskAPI.Step == "DMO Check" & Actions.SelectedValue == "1" & Assessment1.Assessment.Opinion == "1")
            //{
            //    if (DMO_Check_Creation_Number.Text == "" | DMO_Check_Creation_Time.Text == "")
            //    {
            //        regs.Add(new Regular(RegularExp.NotEmpty, "", " DMO Check的Creation项必填"));
            //    }

            //}
            //if (TaskAPI.Step == "DMO Approve" & Actions.SelectedValue != "1" & Assessment1.Assessment.Opinion == "1")
            //{
            //    if (DMO_Arrpvoe_Revision_Number.Text == "" | DMO_Arrpvoe_Revision_Time.Text == "")
            //    {
            //        regs.Add(new Regular(RegularExp.NotEmpty, "", " DMO Approve的Revision项必填"));
            //    }
            //    //if (SA2.Checked & VD_Category.SelectedValue == "1")
            //    //{
            //    //    regs.Add(new Regular(RegularExp.NotEmpty, DMO_SalesSAP_Code.Text, "Sales SAP Code 必填"));
            //    //}
            //}
            //if (TaskAPI.Step == "DMO Maintain" & Actions.SelectedValue != "1" & Assessment1.Assessment.Opinion == "1")
            //{
            //    if (DMO_Maintain_Revision_Number.Text == "" | DMO_Maintain_Revision_Time.Text == "")
            //    {
            //        regs.Add(new Regular(RegularExp.NotEmpty, "", " DMO Maintain的Revision项必填"));
            //    }

            //}
            //if (TaskAPI.Step == "DMO Check" & Actions.SelectedValue != "1" & Assessment1.Assessment.Opinion == "1")
            //{
            //    if (DMO_Check_Revision_Number.Text == "" | DMO_Check_Revision_Time.Text == "")
            //    {
            //        regs.Add(new Regular(RegularExp.NotEmpty, "", " DMO Check的Revision项必填"));
            //    }

            //}
            return Validation(regs);
        }
        #endregion

        #region 重载 OnLoadComplete
        protected override void OnLoadComplete(EventArgs e)
        {
            if (!IsLoaded && TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit)
            {
                Actions_SelectedIndexChanged(null, e);
            }

            base.OnLoadComplete(e);
        }
        #endregion

        #region 方法 SetDropDownListValue
        private void SetDropDownListValue(Anthem.DropDownList drpT, object o)
        {
            try
            {
                if ((TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit) || drpT.Items.FindByValue(o.ToString()) != null)
                {
                    drpT.SelectedValue = o.ToString();
                    return;
                }

                drpT.Items.Add(new ListItem(o.ToString(), o.ToString()));
                drpT.SelectedIndex = 0;

            }
            catch (Exception)
            {
            }
        }
        #endregion

        #region 事件Yes/No
        protected void Yes_No_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (Actions.SelectedValue == "1" && Yes_No.Text == "Yes")
            {
                SetForeColor(Color.Blue, Cost_Element_Category_L);
            }
            else
            {
                SetForeColor(Color.Black, Cost_Element_Category_L);
            }
        }
        #endregion


    }
}